package leetcode.code1033;

import java.util.Arrays;

public class Solution {
	public int[] numMovesStones1(int a, int b, int c) {
		int[] nums = new int[] { a, b, c };
		Arrays.sort(nums);
		int max = nums[1] - nums[0] - 1 + nums[2] - nums[1] - 1;
		int min = 0;
		if (nums[2] - nums[1] == 2 || nums[1] - nums[0] == 2) {
			min = 1;
		} else {
			min = (nums[0] + 1 == nums[1] ? 0 : 1) + (nums[1] + 1 == nums[2] ? 0 : 1);
		}
		return new int[] { min, max };
	}

	public int[] numMovesStones(int a, int b, int c) {
		int m = Math.max(a, Math.max(b, c));
		int s = Math.min(a, Math.min(b, c));
		int sm = a + b + c - m - s;
		int max = m - s - 2;
		int min = 0;
		if (m - sm == 2 || sm - s == 2) {
			min = 1;
		} else {
			min = (s + 1 == sm ? 0 : 1) + (sm + 1 == m ? 0 : 1);
		}
		return new int[] { min, max };
	}
}
